import { hasInterceptors } from "mobx-miniprogram/lib/internal"
import {createStoreBindings} from "mobx-miniprogram-bindings"
import {store} from "../../store/store"
import axios from "../../utils/axios"
// pages/activitymanager/activitymanager.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:0,
    type:0,
    process:['未审核','已通过'],
    currentindex:0,
    auditresumes:[],
    passresumes:[],
    checks:[],
    length:0
  },
  async getactivitysignup(flag,key){
    var token=getApp(). globalData.accessToken
    var url="/"
    switch(this.data.type){
      case 0: url+="activity/information?flag="+flag+"&activityId="+this.data.id
      break
      case 1:url+="project/resume?projectId="+this.data.id+"&pass="+flag
    }
    var result=await axios.get(url)
    this.setData({
      [key]:result
    })
  },
 async tapindex(e){
    this.setData({
      currentindex:e.currentTarget.dataset.index
    })
    if(this.data.currentindex==0){
      this.getactivitysignup(0,"auditresumes")
    }else{
      this.getactivitysignup(1,"passresumes")
    }
  },
  getchecks(e){
   this.setData({
     checks:e.detail
   })
   console.log(this.data.auditresumes)
  },
  showdetail:function(e){
    var index=e.currentTarget.dataset.index
    console.log(index)
    var resume={}
    switch(this.data.type){
      case 0:
        break
      case 1:
        switch(this.data.currentindex){
          case 0:
            resume=this.data.auditresumes[index]
            break
          case 1:
            resume=this.data.passresumes[index]
        }
        console.log(resume)
        wx.navigateTo({
          url:"../talentdetail/talentdetail?talentdetail="+JSON.stringify(resume)+"&mine=false"
        })
    }
  },
  close:function(e){
    wx.showModal({
      title:"是否确定关闭报名",
      success:function(e){
        wx.navigateBack({
          delta:1
        })
      }
    })
  },
  checkbox:function(e){
    var index=e.currentTarget.dataset.index
    this.setData({
      ['instrutions['+index+'].checked']:!this.data.instrutions[index].checked
    })
  },
async pass(e){
   var pass=e.currentTarget.dataset.pass
   var checks=this.data.checks
   console.log(checks)
   var that=this
   var url=""
   switch(this.data.type){
     case 0:
       checks.forEach(check=>{
         url+"&ids="+check
       })
       break
    case 1:
      url+="/project/resume?projectId="+this.data.id
      checks.forEach(check=>{
        url+=("&userIds="+check)
      })
   }
   await axios.patch(url,{})
   await that.getactivitysignup(0,"auditresumes")
 },
   /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(option) {
    console.log(option)
    this.setData({
      id:JSON.parse(option.id),
      type:JSON.parse(option.type)
    })
    console.log(this.data.type)
  this.getactivitysignup(0,"auditresumes")
  this.getactivitysignup(1,"passresumes")
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})